// 防抖
// 实现思路是设置定时器，再次触发时清除定时器
let timer = null;
const fn = (fn, time) => {
  if (timer) {
    clearInterval(timer);
  }

  timer = setTimeout(() => {
    fn();
    timer = null;
  }, time);
};

// 节流
// 实现思路是在事件完成之后吧定时器置为空，并且重复请求直接return
let timer2 = null;
const fn2 = (fn, time) => {
  if (timer2) {
    return;
  }

  timer2 = setTimeout(() => {
    fn();
    timer2 = null;
  }, time);
};
